﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_table_deptgrant : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainPsnInfo");

            migrationBuilder.DropTable(
                name: "MainPosInfo");

            migrationBuilder.CreateTable(
                name: "MainDept",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DeptCodg = table.Column<string>(type: "text", nullable: false),
                    DeptName = table.Column<string>(type: "text", nullable: false),
                    Pinyincode = table.Column<string>(type: "text", nullable: true),
                    Wubicode = table.Column<string>(type: "text", nullable: true),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainDept", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainDept_MainDept_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainDept",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "MainDeptGrant",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProviderKey = table.Column<string>(type: "text", nullable: false),
                    ProviderName = table.Column<string>(type: "text", nullable: false),
                    DeptId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainDeptGrant", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainDeptGrant_MainDept_DeptId",
                        column: x => x.DeptId,
                        principalTable: "MainDept",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainDept_ParentId",
                table: "MainDept",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_MainDeptGrant_DeptId",
                table: "MainDeptGrant",
                column: "DeptId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainDeptGrant");

            migrationBuilder.DropTable(
                name: "MainDept");

            migrationBuilder.CreateTable(
                name: "MainPosInfo",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    PosCodg = table.Column<string>(type: "text", nullable: false),
                    PosName = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainPosInfo", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainPsnInfo",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    PosInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    BEGNTIME = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    BRDY = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    CERTNO = table.Column<string>(type: "text", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    DeptId = table.Column<Guid>(type: "uuid", nullable: false),
                    ENDTIME = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    GEND = table.Column<int>(type: "integer", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    ITRO = table.Column<string>(type: "text", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    MEDINS_PSN_TYPE_CODE = table.Column<string>(type: "text", nullable: true),
                    MEDINS_PSN_TYPE_NAME = table.Column<string>(type: "text", nullable: true),
                    PIC = table.Column<string>(type: "text", nullable: true),
                    PINYINCODE = table.Column<string>(type: "text", nullable: true),
                    PRAC_CERT_NO = table.Column<string>(type: "text", nullable: true),
                    PRAC_PSN_CERT = table.Column<string>(type: "text", nullable: true),
                    PRAC_PSN_CODE = table.Column<string>(type: "text", nullable: true),
                    PROFTTL_CODE = table.Column<string>(type: "text", nullable: true),
                    PROFTTL_NAME = table.Column<string>(type: "text", nullable: true),
                    PSN_CERT_TYPE_CODE = table.Column<string>(type: "text", nullable: true),
                    PSN_CERT_TYPE_NAME = table.Column<string>(type: "text", nullable: true),
                    PSN_CODG = table.Column<string>(type: "text", nullable: false),
                    PSN_NAME = table.Column<string>(type: "text", nullable: false),
                    SKILL = table.Column<string>(type: "text", nullable: true),
                    TEL = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    USER_ID = table.Column<Guid>(type: "uuid", nullable: true),
                    WUBICODE = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainPsnInfo", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainPsnInfo_MainPosInfo_PosInfoId",
                        column: x => x.PosInfoId,
                        principalTable: "MainPosInfo",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainPsnInfo_PosInfoId",
                table: "MainPsnInfo",
                column: "PosInfoId");
        }
    }
}
